﻿using AntMovement.Core;
using AntMovement.Core.Attributes;
using AntMovement.Core.Entity;
using AntMovement.Core.Hardware;
using AntMovement.Core.IParameter;
using AntMovement.Core.Logic;
using AntMovement.Parameter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.Handle.BluingFilm
{
    [FlowAttributes(nameof(FilmFeeding), 5)]
    public class FilmFeeding : TaskBase
    {
        #region 轴变量
        private IAxis _axitSix;
        private AxisStatus _axisStatusSix;
        #endregion
        #region 输入点
        private NormalOpen _物料吸盘检测光纤;
        #endregion
        #region 输出点

        #endregion
        #region 定时器
        private Ton _物料吸盘Time = new Ton();
        #endregion
        #region 上升沿
        private bool _sixRisingEdge = false;
        #endregion
        #region 报警变量

        #endregion
        #region 私有变量

        #endregion
        public FilmFeeding(ITemporaryParameter temporary, IIOParameter iop, IAxisParameter axisp, IDialogHost dialogHost, ILog log)
            : base(temporary, iop, axisp, dialogHost, log)
        {
            _axitSix = axisp.GetAxis("贴膜送料轴");
            _axisStatusSix = _axitSix.GetAxisStatus();
            _物料吸盘检测光纤 = iop.GetNormalOpen("物料吸盘检测光纤");
        }

        public override void Handle()
        {
            if (_temporary.SystemStatus.Auto)
            {
                if (!_物料吸盘检测光纤.Execute())
                {
                    _物料吸盘Time.Time(400, true);
                    if (_物料吸盘Time.Out)
                    {
                        if (!_axisStatusSix.SportStatus)
                        {
                            _axitSix.ContinuousMotion(true);
                        }
                    }
                }
                else
                {
                    if (_temporary.MaterielCount == 0 && _axisStatusSix.SportStatus)
                    {
                        _temporary.MaterielCount = 2;
                    }
                    _物料吸盘Time.Time(400, false);
                    _axitSix.Stop(1);
                }
            }
            if (_temporary.SystemStatus.ManualOperation)
            {
            }
        }

        public override void Resetting()
        {

        }

        public override void SafeStop()
        {
            _axitSix.Stop(1);
        }

        public override void EmergencyStop()
        {
            _axitSix.Stop(1);
        }
    }
}
